
package com.hlkj.pay.service.merchant.impl;
/*
 * Hlpay-Plus aggregate payment system.
 * Copyright (c) 2024-2025 Hlpay Team Copyright has the right of final interpretation.
 */

import java.util.List;

import org.springframework.stereotype.Service;

import com.hlkj.framework.common.pojo.PageResult;
import com.hlkj.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.hlkj.pay.dto.fund.FundConfigQueryDto;
import com.hlkj.pay.infrastructure.mapper.merchant.fund.MerchantFundAccountConfigMapper;
import com.hlkj.pay.infrastructure.model.merchant.fund.MerchantFundAccountConfigDO;
import com.hlkj.pay.service.CommonSnFilterService;
import com.hlkj.pay.service.merchant.IMerchantFundAccountConfigService;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @author HlpayTeam
 * @date 2025/01/08 17:07
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class MerchantFundAccountConfigServiceImpl extends CommonSnFilterService implements IMerchantFundAccountConfigService {

    private final MerchantFundAccountConfigMapper merchantFundAccountBindMapper;

    @Override
    public MerchantFundAccountConfigDO detail(Long id) {
        return merchantFundAccountBindMapper.selectById(id);
    }

    @Override
    public PageResult<MerchantFundAccountConfigDO> queryPage(FundConfigQueryDto fundQueryDto) {
        return merchantFundAccountBindMapper.selectPage(fundQueryDto, buildInfoWrapper(fundQueryDto));
    }

    @Override
    public List<MerchantFundAccountConfigDO> queryList(FundConfigQueryDto fundQueryDto) {
        return merchantFundAccountBindMapper.selectList(buildInfoWrapper(fundQueryDto));
    }

    @Override
    public void addConfig(MerchantFundAccountConfigDO fundAccountConfigDO) {
        merchantFundAccountBindMapper.insert(fundAccountConfigDO);
    }

    @Override
    public void updateConfig(MerchantFundAccountConfigDO defaultFeeConfigDO) {
        merchantFundAccountBindMapper.updateById(defaultFeeConfigDO);
    }

    @Override
    public void delConfig(Long id) {
        merchantFundAccountBindMapper.deleteById(id);
    }


    private LambdaQueryWrapperX<MerchantFundAccountConfigDO> buildInfoWrapper(FundConfigQueryDto fundConfigQueryDto) {
        LambdaQueryWrapperX<MerchantFundAccountConfigDO> queryWrapper = new LambdaQueryWrapperX<>();
        queryWrapper.eqIfPresent(MerchantFundAccountConfigDO::getSn, fundConfigQueryDto.getSn());
        queryWrapper.eqIfPresent(MerchantFundAccountConfigDO::getProviderCode, fundConfigQueryDto.getProviderCode());
        queryWrapper.eqIfPresent(MerchantFundAccountConfigDO::getChannelCode, fundConfigQueryDto.getChannelCode());
        queryWrapper.eqIfPresent(MerchantFundAccountConfigDO::getAppId, fundConfigQueryDto.getAppId());
        queryWrapper.eqIfPresent(MerchantFundAccountConfigDO::getSnVisible, fundConfigQueryDto.getSnVisible());
        queryWrapper.eqIfPresent(MerchantFundAccountConfigDO::getAccountNo, fundConfigQueryDto.getAccountNo());
        queryWrapper.eqIfPresent(MerchantFundAccountConfigDO::getStatus, fundConfigQueryDto.getStatus());
        queryWrapper.eqIfPresent(MerchantFundAccountConfigDO::getType, fundConfigQueryDto.getType());
        queryWrapper.likeIfPresent(MerchantFundAccountConfigDO::getName, fundConfigQueryDto.getName());
        queryWrapper.geIfPresent(MerchantFundAccountConfigDO::getCreateTime, fundConfigQueryDto.getStartQueryTime());
        queryWrapper.leIfPresent(MerchantFundAccountConfigDO::getCreateTime, fundConfigQueryDto.getEndQueryTime());
        return queryWrapper;
    }
}
